package com.snopy.mq.activemq;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author snopy
 * @description:
 * @classname JmsProducer
 * @date 2020/12/18 9:07
 * @email 77912204@qq.com
 */
public class JmsProducer {
    public static void main(String[] args) throws JMSException {
        //1 创建消息服务器工厂
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setBrokerURL("tcp://192.168.5.136:61616");
        //2 创建连接
        Connection connection = connectionFactory.createConnection();
        //连接
        connection.start();
        //3 创建会话session
        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        //4 创建目的地
        Topic mytopic = session.createTopic("mytopic");
        //5 创建消息的生产者
        MessageProducer messageProducer = session.createProducer(mytopic);
        //
        messageProducer.send(session.createTextMessage("hello it's me 0"));
        messageProducer.send(session.createTextMessage("hello it's me 1"));
        messageProducer.send(session.createTextMessage("hello it's me 2"));
        messageProducer.send(session.createTextMessage("hello it's me 3"));
        messageProducer.send(session.createTextMessage("hello it's me 4"));
        messageProducer.send(session.createTextMessage("hello it's me 5"));
        messageProducer.send(session.createTextMessage("hello it's me 6"));
        messageProducer.send(session.createTextMessage("hello it's me 7"));
        messageProducer.send(session.createTextMessage("hello it's me 8"));
        messageProducer.send(session.createTextMessage("hello it's me 9"));
        messageProducer.send(session.createTextMessage("hello it's me 10"));

        messageProducer.close();
        session.close();
        connection.close();

    }
}
